def sieve_of_eratosthenes(k):
    is_prime = [True] * (k + 1)
    is_prime[0] = is_prime[1] = False  # 0和1不是素数
    for i in range(2, int(k ** 0.5) + 1):
        if is_prime[i]:
            for j in range(i * i, k + 1, i):
                is_prime[j] = False
    return [i for i in range(k + 1) if is_prime[i]]
def print_primes(g):
    for i in range(len(g)):
        print(g[i], end=' ')
        if (i + 1) % 5 == 0:
            print()  # 每5个素数换行
    if len(g) % 5 != 0:
        print()  # 如果最后一行不满5个，换行
# 主程序
limit = 20000
primes = sieve_of_eratosthenes(limit)
print_primes(primes)
